package com.controller;

import com.pojo.ResponsePojo;
import com.pojo.User;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/user")
public class UserController {
    private UserService userService;
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    //查找全部
    @GetMapping("/findAll")
    public ResponsePojo findAll(){
        return userService.findAll();
    }

    @PostMapping("/login")
    public ModelAndView login(String username, String password){
        ModelAndView modelAndView = new ModelAndView();
        User user = userService.login(username, password);
        modelAndView.addObject("user",user);
        modelAndView.setViewName("/index.jsp");
        return modelAndView;
    }
}
